
namespace gen {

	///////////////////////////////////////////////////////////////////////////
    //
    //  limits class implementation
    //
    ///////////////////////////////////////////////////////////////////////////

	template <class LimitT>
	inline limits<LimitT> 
	operator,( limit_base<LimitT,typename LimitT::context_t> const& b1,
			   limit_base<LimitT,typename LimitT::context_t> const& b2)
	{
		return limits<LimitT>(b1.derived(), b2.derived());
	}


	template <class LimitT>
	inline limits<LimitT>            
	operator,( limit_base<LimitT,typename LimitT::context_t> const& b1, 
			   int offset)
	{
		LimitT b2(limit_base<LimitT,typename LimitT::context_t>::beg, offset);
		return limits<LimitT>(b1, b2);
	}

	template <class LimitT>
	inline limits<LimitT>            
	operator,( int offset,
			   limit_base<LimitT,typename LimitT::context_t> const& b2)
	{
		LimitT b1(limit_base<LimitT,typename LimitT::context_t>::beg, offset);
		return limits<LimitT>(b1, b2);
	}

	template <class LimitT>
	typename limits<LimitT>::iterator_t 
	limits<LimitT>::first(parent_t const& p) const
	{
		return l_first.get_limit(p);
	}

	template <class LimitT>
	typename limits<LimitT>::iterator_t 
	limits<LimitT>::last(parent_t const& p) const
	{
		return l_last.get_limit(p);
	}

	///////////////////////////////////////////////////////////////////////////
    //
    //  loop class implementation
    //
    ///////////////////////////////////////////////////////////////////////////

	template <typename S, typename LimitsT>
	template <typename ContextT>
	void
	loop<S,LimitsT>::generate(ContextT & info) const
    {
		typedef typename LimitsT::iterator_t		iterator_t;
		typedef typename LimitsT::context_t			context_t;

		iterator_t first = this->right().first(info);
		iterator_t last = this->right().last(info);
		context_t c(first, last, info);

		for (iterator_t i = first; i != last; ++i)
        {
			c.current(i);
            this->left().generate(c);
        }
		//info.reset(c.str());
    }

    template <typename DerivedT>
	template <class LimitT>
	inline loop< DerivedT, limits<LimitT> >
	generator<DerivedT>::operator[](limits<LimitT> const& l) const
    {
        return loop<DerivedT, limits<LimitT> >(derived(), l);
    }

}
